# delimit ;
clear ;
set more off ;
est drop _all ;
cd "R:/personlig/fenellac/menarche_replication/analysis/" ;

global plusdir "R:/personlig/fenellac/stata_ado/plus/" ;
sysdir set PLUS $plusdir ;
adopath ++ $plusdir ;

* **************************************************************************** ;
* This code replicates Appendix C, Tables 1-3.
*
* Paper: "Age of Marriage and Women's Political Engagement: Evidence from India"
* Authors: Fenella Carpena, Francesca Jensenius
* 
* Code by Fenella Carpena
* Last update: May 4, 2020
* **************************************************************************** ;

****************************************************************************** ;
* select the sample
****************************************************************************** ;

use "./input/eligible-women-ihds02-lhs.dta", clear ;
merge 1:1 IDHH PERSONID using "./input/eligible-women-ihds02-rhs.dta" ;
tab _merge ;
assert _merge == 3 ;
drop _merge ;

* keep only women who are married only once (i.e., have not ever remarried) ;
drop if ever_remarried == 1 ;
  
* keep only women age of menarche between 11-18 (1st-99th pctile) ; 
summ menarche_age ;
keep if menarche_age >= 11 & menarche_age <= 18 ;

* generating district identifier ;
egen dt_id = group(STATEID DISTID) ;

****************************************************************************** ;
* TABLE first-stage regressions
****************************************************************************** ;
foreach s in "full" "rural" "urban" { ;

preserve ;

if "`s'" == "full" local sample "" ;
else if "`s'" == "rural" local sample "if rural == 1" ;
else if "`s'" == "urban" local sample "if rural == 0" ;

est drop _all ;
 
areg marriage_age menarche_age `sample', robust a(dt_id);
est sto first_stage1 ;
test menarche_age ;
estadd scalar fstat = r(F) ;
estadd local distFE "Yes" ;

areg marriage_age menarche_age height_measure hindu muslim sc st obc age `sample' , robust a(dt_id);
est sto first_stage2 ;
test menarche_age ;
estadd scalar fstat = r(F) ;
estadd local distFE "Yes" ;

areg marriage_age menarche_age height_measure hindu muslim sc st obc age mother_yrs_educ father_yrs_educ `sample' , robust a(dt_id);
est sto first_stage3 ;
test menarche_age ;
estadd scalar fstat = r(F) ;
estadd local distFE "Yes" ;

areg marriage_age menarche_age height_measure hindu muslim sc st obc age mother_yrs_educ father_yrs_educ years_schooling `sample' , robust a(dt_id);
est sto first_stage4 ;
test menarche_age ;
estadd scalar fstat = r(F) ;
estadd local distFE "Yes" ;

areg marriage_age menarche_age height_measure hindu muslim sc st obc age mother_yrs_educ father_yrs_educ ever_schooled `sample' , robust a(dt_id);
est sto first_stage5 ;
test menarche_age ;
estadd scalar fstat = r(F) ;
estadd local distFE "Yes" ;

* dummy variables for menarche age ;
forvalues i = 12/18 { ;
	gen dmenarche`i' = menarche_age == `i' ;
	label var dmenarche`i' "Menarche Age = `i'" ;
} ;

areg marriage_age dmenarche* height_measure hindu muslim sc st obc age mother_yrs_educ father_yrs_educ  `sample' , robust a(dt_id);
est sto first_stage6 ;
test dmenarche12 dmenarche13 dmenarche14 dmenarche15 dmenarche16 dmenarche17 dmenarche18 ;
estadd scalar fstat = r(F) ;
estadd local distFE "Yes" ;

* label variables for the output table ;
label var menarche_age "Menarche Age" ;
label var gauna_age "\shortstack{Cohabitation\\ Age}" ;
label var marriage_age "Marriage Age" ;
label var height_measure "Height (cm)" ;
label var hindu "Hindu" ;
label var muslim "Muslim" ;
label var sc "Scheduled Caste" ;
label var st "Scheduled Tribe" ;
label var obc "Other Backward Class" ;
label var age "Age" ;
label var mother_yrs_educ "Mother's Years of Education" ;
label var father_yrs_educ "Father's Years of Education" ;
label var years_schooling "Years Education Completed" ;
label var ever_schooled "Ever Attended School" ;

if "`s'" == "full" local title "Rural and Urban Women" ;
else if "`s'" == "rural" local title "Rural Women"  ;
else if "`s'" == "urban" local title "Urban Women"  ;

if "`s'" == "full" local note "full sample of rural and urban women" ;
else if "`s'" == "rural" local note "rural women"  ;
else if "`s'" == "urban" local note "urban women"  ;

* LaTeX output ;
esttab first_stage* using "./output/table-first-stage-`s'.tex",
	replace
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) drop(_cons)
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(distFE fstat N, fmt(%20s %9.3f %9.0f) labels("District Fixed Effects" "Instrument F-stat" "Observations"))
	prehead(\begin{table}[h!]\centering \small `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"'
		\captionsetup{justification=centering} 
		\caption{First Stage Regressions, `title'}
		\label{table-first-stage-`s'}
		\begin{tabular*}{\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{@E}{p{1.5cm}}}
		\toprule)
	nodepvars nomtitles
	legend label  booktabs  collabels( , none)
	postfoot(`"\bottomrule"'  \end{tabular*} \captionsetup{justification=justified, width=\hsize} 
		\caption*{\footnotesize \textit{Notes:} 
		OLS regressions for the IV first stage. The dependent variable is marriage age. The first stage specification used throughout the analysis corresponds to column 3. 
		Columns 4 and 5 control for respondent's education and are shown as a robustness check. Column 6 allows for non-linearity in the effect of menarche age.
		Data from IHDS 2011--12, `note'. Robust SEs in parenthesis. ***\$\,p < 0.01$, **\$\,p < 0.05$, *\$\,p<0.10$.}
		\end{table}) ;

restore ;

};
	
exit ;

